package com.taptech.doufu.ui.view.userdetail

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.google.gson.Gson
import com.taptech.doufu.R
import com.taptech.doufu.model.user.FansRankBean
import com.taptech.doufu.model.user.ListItem
import com.taptech.doufu.ui.activity.UserDetailActivity
import com.taptech.doufu.ui.activity.weex.SimpleWeexActivity
import com.taptech.doufu.util.GlideUtil
import com.taptech.doufu.util.GsonUtil
import kotlinx.android.synthetic.main.view_user_detail_fans_rank.view.*

class UserDetailFansRankView(context: Context) : LinearLayout(context) {

    init {
        initView()
    }

    private fun initView() {
        val view = LayoutInflater.from(context).inflate(R.layout.view_user_detail_fans_rank,null)
        addView(view)
    }

    fun setData(uid:Int,data: ListItem) {
        try {
            val info = GsonUtil.parseJsonWithGson(Gson().toJson(data.data), FansRankBean::class.java)
            val list = info.list
            if (list != null) {
                if (list.size > 0) {
                    layFans1.visibility = View.VISIBLE
                    GlideUtil.displayCircleImage(context,ivFans1,list[0].userInfo.head_image)
                }else{
                    layFans1.visibility = View.GONE
                }

                if (list.size > 1) {
                    layFans2.visibility = View.VISIBLE
                    GlideUtil.displayCircleImage(context,ivFans2,list[1].userInfo.head_image)
                }else{
                    layFans2.visibility = View.GONE
                }

                if (list.size > 2) {
                    layFans3.visibility = View.VISIBLE
                    GlideUtil.displayCircleImage(context,ivFans3,list[2].userInfo.head_image)
                }else{
                    layFans3.visibility = View.GONE
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
        setOnClickListener {
            val map = HashMap<String, Any>()
            map["uid"] = uid
            SimpleWeexActivity.startActivity(context,"vue/user/TFUserBigFansList.js",map)
        }
    }
}